/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * JF_TestLib.java
 *
 * Created on 25 mars 2010, 08:26:58
 */
package testLib;

import bluenext.CommonInterface;
import bluenext.ErreurNXTException;
import java.io.File;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import lejos.nxt.remote.DeviceInfo;
import lejos.nxt.remote.FileInfo;
import lejos.nxt.remote.FirmwareInfo;
import lejos.nxt.remote.OutputState;
import lejos.pc.comm.NXTCommException;

/**
 *
 * @author Administrateur
 */
public class JF_TestLib extends javax.swing.JFrame {

    private CommonInterface ci;
    private String nomsRobots[];

    /** Creates new form JF_TestLib */
    public JF_TestLib(CommonInterface comI) {
        ci = comI;
        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jbRechercheNXT = new javax.swing.JButton();
        jbConnexion = new javax.swing.JButton();
        listeNomRobots = new java.awt.List();
        jpWiimote = new javax.swing.JPanel();
        jbHaut = new javax.swing.JButton();
        jbBas = new javax.swing.JButton();
        jbGauche = new javax.swing.JButton();
        jbDroite = new javax.swing.JButton();
        jbA = new javax.swing.JButton();
        jbB = new javax.swing.JButton();
        jbAdr = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        jtaInfosDiverses = new javax.swing.JTextArea();
        jLabel1 = new javax.swing.JLabel();
        jbClear = new javax.swing.JButton();
        jbEnvoyerFichier = new javax.swing.JButton();
        jbPlay = new javax.swing.JButton();
        jbAutoTest = new javax.swing.JButton();
        jbDeconnexion = new javax.swing.JButton();
        jTextField1 = new javax.swing.JTextField();
        jbRenommer = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jbRechercheNXT.setText("Recherche NXT");
        jbRechercheNXT.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbRechercheNXTActionPerformed(evt);
            }
        });

        jbConnexion.setText("Connexion");
        jbConnexion.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbConnexionActionPerformed(evt);
            }
        });

        listeNomRobots.setMultipleMode(true);

        jbHaut.setText("Haut");
        jbHaut.setMaximumSize(new java.awt.Dimension(69, 23));
        jbHaut.setPreferredSize(new java.awt.Dimension(69, 23));
        jbHaut.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbHautActionPerformed(evt);
            }
        });

        jbBas.setText("Bas");
        jbBas.setPreferredSize(new java.awt.Dimension(69, 23));
        jbBas.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbBasActionPerformed(evt);
            }
        });

        jbGauche.setText("Gauche");
        jbGauche.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbGaucheActionPerformed(evt);
            }
        });

        jbDroite.setText("Droite");
        jbDroite.setPreferredSize(new java.awt.Dimension(69, 23));
        jbDroite.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbDroiteActionPerformed(evt);
            }
        });

        jbA.setText("Bip");
        jbA.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbAActionPerformed(evt);
            }
        });

        jbB.setText("Stop");
        jbB.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbBActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jpWiimoteLayout = new javax.swing.GroupLayout(jpWiimote);
        jpWiimote.setLayout(jpWiimoteLayout);
        jpWiimoteLayout.setHorizontalGroup(
            jpWiimoteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jpWiimoteLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jpWiimoteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jpWiimoteLayout.createSequentialGroup()
                        .addGap(51, 51, 51)
                        .addGroup(jpWiimoteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jbBas, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 56, Short.MAX_VALUE)
                            .addComponent(jbHaut, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 56, Short.MAX_VALUE))
                        .addGap(51, 51, 51))
                    .addGroup(jpWiimoteLayout.createSequentialGroup()
                        .addComponent(jbGauche, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addGap(18, 18, 18)
                        .addComponent(jbDroite, javax.swing.GroupLayout.DEFAULT_SIZE, 61, Short.MAX_VALUE)
                        .addContainerGap())
                    .addGroup(jpWiimoteLayout.createSequentialGroup()
                        .addComponent(jbA)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 46, Short.MAX_VALUE)
                        .addComponent(jbB)
                        .addContainerGap())))
        );
        jpWiimoteLayout.setVerticalGroup(
            jpWiimoteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jpWiimoteLayout.createSequentialGroup()
                .addGap(17, 17, 17)
                .addComponent(jbHaut, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jpWiimoteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jbGauche)
                    .addComponent(jbDroite, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGroup(jpWiimoteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(jpWiimoteLayout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jbBas, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addContainerGap(37, Short.MAX_VALUE))
                    .addGroup(jpWiimoteLayout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jpWiimoteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jbA)
                            .addComponent(jbB))
                        .addContainerGap())))
        );

        jbAdr.setText("Adresse");
        jbAdr.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbAdrActionPerformed(evt);
            }
        });

        jtaInfosDiverses.setColumns(20);
        jtaInfosDiverses.setEditable(false);
        jtaInfosDiverses.setRows(5);
        jScrollPane1.setViewportView(jtaInfosDiverses);

        jLabel1.setText("Informations diverses:");

        jbClear.setText("Clear");
        jbClear.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbClearActionPerformed(evt);
            }
        });

        jbEnvoyerFichier.setText("Envoyer fichier");
        jbEnvoyerFichier.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbEnvoyerFichierActionPerformed(evt);
            }
        });

        jbPlay.setText("Jouer fichier");
        jbPlay.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbPlayActionPerformed(evt);
            }
        });

        jbAutoTest.setText("Auto_test");
        jbAutoTest.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbAutoTestActionPerformed(evt);
            }
        });

        jbDeconnexion.setText("Deconnexion");
        jbDeconnexion.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbDeconnexionActionPerformed(evt);
            }
        });

        jbRenommer.setText("Renommer");
        jbRenommer.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbRenommerActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 441, Short.MAX_VALUE)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jbRechercheNXT, javax.swing.GroupLayout.DEFAULT_SIZE, 132, Short.MAX_VALUE)
                                .addGap(16, 16, 16))
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(listeNomRobots, javax.swing.GroupLayout.DEFAULT_SIZE, 138, Short.MAX_VALUE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)))
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jbDeconnexion, javax.swing.GroupLayout.DEFAULT_SIZE, 111, Short.MAX_VALUE)
                            .addComponent(jbAutoTest, javax.swing.GroupLayout.DEFAULT_SIZE, 111, Short.MAX_VALUE)
                            .addComponent(jbAdr, javax.swing.GroupLayout.DEFAULT_SIZE, 111, Short.MAX_VALUE)
                            .addComponent(jbEnvoyerFichier, javax.swing.GroupLayout.DEFAULT_SIZE, 111, Short.MAX_VALUE)
                            .addComponent(jbPlay, javax.swing.GroupLayout.DEFAULT_SIZE, 111, Short.MAX_VALUE)
                            .addComponent(jbConnexion, javax.swing.GroupLayout.DEFAULT_SIZE, 111, Short.MAX_VALUE))
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                .addComponent(jTextField1)
                                .addComponent(jpWiimote, javax.swing.GroupLayout.DEFAULT_SIZE, 164, Short.MAX_VALUE))
                            .addComponent(jbRenommer)))
                    .addComponent(jLabel1)
                    .addComponent(jbClear))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jbRechercheNXT)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jbConnexion)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jbAdr)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jbEnvoyerFichier)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jbPlay)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                    .addComponent(jbAutoTest)
                                    .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                    .addComponent(jbDeconnexion)
                                    .addComponent(jbRenommer)))
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(listeNomRobots, javax.swing.GroupLayout.PREFERRED_SIZE, 174, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jLabel1))))
                    .addComponent(jpWiimote, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 167, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jbClear)
                .addContainerGap(11, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jbRechercheNXTActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbRechercheNXTActionPerformed
        try {
            // TODO add your handling code here:
            nomsRobots = ci.search();
        } catch (ErreurNXTException ex) {
            Logger.getLogger(JF_TestLib.class.getName()).log(Level.SEVERE, null, ex);
        }

        if (nomsRobots == (null) || nomsRobots.length == 0) {// | nomsRobots.length==0){
            System.out.println("Aucun NXT a proximite");
            listeNomRobots.add("Aucun NXT a proximite");
        } else {
            for (int i = 0; i < nomsRobots.length; i++) {
                System.out.println(i + ". " + nomsRobots[i]);
                listeNomRobots.add(nomsRobots[i]);
            }
        }

    }//GEN-LAST:event_jbRechercheNXTActionPerformed

    private void jbHautActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbHautActionPerformed
        // TODO add your handling code here:
        String robots[] = listeNomRobots.getSelectedItems();

        for (int i = 0; i < robots.length; i++) {
            try {
                ci.setOutputState(robots[i], 0, Byte.parseByte("80"), lejos.nxt.remote.NXTProtocol.MOTORON, lejos.nxt.remote.NXTProtocol.REGULATED, 80, lejos.nxt.remote.NXTProtocol.MOTOR_RUN_STATE_RUNNING, 0);
                ci.setOutputState(robots[i], 1, Byte.parseByte("80"), lejos.nxt.remote.NXTProtocol.MOTORON, lejos.nxt.remote.NXTProtocol.REGULATED, 80, lejos.nxt.remote.NXTProtocol.MOTOR_RUN_STATE_RUNNING, 0);
            } catch (ErreurNXTException ex) {
                Logger.getLogger(JF_TestLib.class.getName()).log(Level.SEVERE, null, ex);
            } catch (IOException ex) {
                Logger.getLogger(JF_TestLib.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    }//GEN-LAST:event_jbHautActionPerformed

    private void jbGaucheActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbGaucheActionPerformed
        // TODO add your handling code here:
        String robots[] = listeNomRobots.getSelectedItems();

        for (int i = 0; i < robots.length; i++) {
            try {
                ci.setOutputState(robots[i], 0, Byte.parseByte("80"), lejos.nxt.remote.NXTProtocol.MOTORON, lejos.nxt.remote.NXTProtocol.REGULATED, 0, lejos.nxt.remote.NXTProtocol.MOTOR_RUN_STATE_RUNNING, 0);
                ci.setOutputState(robots[i], 1, Byte.parseByte("-80"), lejos.nxt.remote.NXTProtocol.MOTORON, lejos.nxt.remote.NXTProtocol.REGULATED, 0, lejos.nxt.remote.NXTProtocol.MOTOR_RUN_STATE_RUNNING, 0);
            } catch (ErreurNXTException ex) {
                Logger.getLogger(JF_TestLib.class.getName()).log(Level.SEVERE, null, ex);
            } catch (IOException ex) {
                Logger.getLogger(JF_TestLib.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    }//GEN-LAST:event_jbGaucheActionPerformed

    private void jbDroiteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbDroiteActionPerformed
        // TODO add your handling code here:
        String robots[] = listeNomRobots.getSelectedItems();

        for (int i = 0; i < robots.length; i++) {
            try {
                ci.setOutputState(robots[i], 0, Byte.parseByte("-80"), lejos.nxt.remote.NXTProtocol.MOTORON, lejos.nxt.remote.NXTProtocol.REGULATED, 0, lejos.nxt.remote.NXTProtocol.MOTOR_RUN_STATE_RUNNING, 0);
                ci.setOutputState(robots[i], 1, Byte.parseByte("80"), lejos.nxt.remote.NXTProtocol.MOTORON, lejos.nxt.remote.NXTProtocol.REGULATED, 0, lejos.nxt.remote.NXTProtocol.MOTOR_RUN_STATE_RUNNING, 0);
            } catch (ErreurNXTException ex) {
                Logger.getLogger(JF_TestLib.class.getName()).log(Level.SEVERE, null, ex);
            } catch (IOException ex) {
                Logger.getLogger(JF_TestLib.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    }//GEN-LAST:event_jbDroiteActionPerformed

    private void jbBasActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbBasActionPerformed
        // TODO add your handling code here:
        String robots[] = listeNomRobots.getSelectedItems();

        for (int i = 0; i < robots.length; i++) {
            try {
                ci.setOutputState(robots[i], 0, Byte.parseByte("-80"), lejos.nxt.remote.NXTProtocol.MOTORON, lejos.nxt.remote.NXTProtocol.REGULATED, 0, lejos.nxt.remote.NXTProtocol.MOTOR_RUN_STATE_RUNNING, 0);
                ci.setOutputState(robots[i], 1, Byte.parseByte("-80"), lejos.nxt.remote.NXTProtocol.MOTORON, lejos.nxt.remote.NXTProtocol.REGULATED, 0, lejos.nxt.remote.NXTProtocol.MOTOR_RUN_STATE_RUNNING, 0);
            } catch (ErreurNXTException ex) {
                Logger.getLogger(JF_TestLib.class.getName()).log(Level.SEVERE, null, ex);
            } catch (IOException ex) {
                Logger.getLogger(JF_TestLib.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    }//GEN-LAST:event_jbBasActionPerformed

    private void jbAActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbAActionPerformed
        // TODO add your handling code here:
        String robots[] = listeNomRobots.getSelectedItems();

        for (int i = 0; i < robots.length; i++) {
            try {
                try {
                    ci.playTone(robots[i], 1000, 5);
                } catch (ErreurNXTException ex) {
                    Logger.getLogger(JF_TestLib.class.getName()).log(Level.SEVERE, null, ex);
                }
            } catch (IOException ex) {
                Logger.getLogger(JF_TestLib.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    }//GEN-LAST:event_jbAActionPerformed

    private void jbBActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbBActionPerformed
        // TODO add your handling code here:
        String robots[] = listeNomRobots.getSelectedItems();

        for (int i = 0; i < robots.length; i++) {
            try {
                ci.setOutputState(robots[i], 0, Byte.parseByte("0"), lejos.nxt.remote.NXTProtocol.MOTOR_RUN_STATE_IDLE, lejos.nxt.remote.NXTProtocol.REGULATED, 80, lejos.nxt.remote.NXTProtocol.MOTOR_RUN_STATE_RUNNING, -360);
                ci.setOutputState(robots[i], 1, Byte.parseByte("0"), lejos.nxt.remote.NXTProtocol.MOTOR_RUN_STATE_IDLE, lejos.nxt.remote.NXTProtocol.REGULATED, 80, lejos.nxt.remote.NXTProtocol.MOTOR_RUN_STATE_RUNNING, -360);
            } catch (ErreurNXTException ex) {
                Logger.getLogger(JF_TestLib.class.getName()).log(Level.SEVERE, null, ex);
            } catch (IOException ex) {
                Logger.getLogger(JF_TestLib.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    }//GEN-LAST:event_jbBActionPerformed

    private void jbConnexionActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbConnexionActionPerformed
        // TODO add your handling code here:
        String robots[] = listeNomRobots.getSelectedItems();
        boolean res;

        for (int i = 0; i < robots.length; i++) {
            try {
                res = ci.connect(robots[i]);
                jtaInfosDiverses.append("Connexion a " + robots[i] + " : " + res + "\n");
                System.out.println("Connexion a " + robots[i] + " : " + res);
            } catch (ErreurNXTException ex) {
                Logger.getLogger(JF_TestLib.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    }//GEN-LAST:event_jbConnexionActionPerformed

    private void jbAdrActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbAdrActionPerformed
        // TODO add your handling code here:
        String adresse;
        String robots[] = listeNomRobots.getSelectedItems();

        for (int i = 0; i < robots.length; i++) {
            adresse = ci.getAddressByName(robots[i]);
            jtaInfosDiverses.append("Nom: " + robots[i] + ", adresse: " + adresse + "\n");
        }
    }//GEN-LAST:event_jbAdrActionPerformed

    private void jbClearActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbClearActionPerformed
        jtaInfosDiverses.setText("");
    }//GEN-LAST:event_jbClearActionPerformed

    private void jbEnvoyerFichierActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbEnvoyerFichierActionPerformed
        // TODO add your handling code here:
        String robots[] = listeNomRobots.getSelectedItems();

        for (int i = 0; i < robots.length; i++) {
            try {
                try {
                    ci.uploadFile(robots[i], new File("F:/test2.wav"), "test2.wav");
                } catch (ErreurNXTException ex) {
                    Logger.getLogger(JF_TestLib.class.getName()).log(Level.SEVERE, null, ex);
                }
            } catch (IOException ex) {
                Logger.getLogger(JF_TestLib.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    }//GEN-LAST:event_jbEnvoyerFichierActionPerformed

    private void jbPlayActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbPlayActionPerformed
        // TODO add your handling code here:
        String robots[] = listeNomRobots.getSelectedItems();

        for (int i = 0; i < robots.length; i++) {
            try {
                try {
                    System.out.println("playSoundFile (" + robots[i] + ") " + ci.playSoundFile(robots[i], "test2.wav", true));
                } catch (ErreurNXTException ex) {
                    Logger.getLogger(JF_TestLib.class.getName()).log(Level.SEVERE, null, ex);
                }
            } catch (IOException ex) {
                Logger.getLogger(JF_TestLib.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    }//GEN-LAST:event_jbPlayActionPerformed

    private void jbAutoTestActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbAutoTestActionPerformed
        // TODO add your handling code here:
        String robots[] = listeNomRobots.getSelectedItems();
        String adresse, nom;
        DeviceInfo diTmp;
        FirmwareInfo fiTmp;
        OutputState opTmp;

        adresse = "00165306DEF2";
        nom = "John Doe";
        byte tab[];
        tab = new byte[2];
        byte port = 0;
        byte lg = 2;

        for (int i = 0; i < robots.length; i++) {
            try {
                jtaInfosDiverses.append("Connexion a " + robots[i] + " : " + ci.connect(robots[i]) + "\n");
                adresse = ci.getAddressByName(robots[i]);
                jtaInfosDiverses.append("Adresse de " + robots[i] + " : " + adresse + "\n");
                ci.disconnect(robots[i]);
                jtaInfosDiverses.append("Deconnexion a " + robots[i] + "\n");
                jtaInfosDiverses.append("Connexion a " + robots[i] + " (adresse) : " + ci.connect(robots[i], adresse) + "\n");

                jtaInfosDiverses.append(robots[i] + " batterie: " + ci.getBatteryLevel(robots[i]) + "\n");

                jtaInfosDiverses.append(robots[i] + " - getInputValue : " + ci.getInputValues(robots[i], 0) + "\n");
                jtaInfosDiverses.append(robots[i] + " - getOutputState : " + ci.getOutputState(robots[i], 0) + "\n");
                ci.setOutputState(robots[i], 0, Byte.parseByte("80"), lejos.nxt.remote.NXTProtocol.MOTORON, lejos.nxt.remote.NXTProtocol.REGULATED, 80, lejos.nxt.remote.NXTProtocol.MOTOR_RUN_STATE_RUNNING, 45);
                ci.setInputMode(robots[i], 0, WIDTH, NORMAL);
                jtaInfosDiverses.append(robots[i] + " - resetMotorPosition : " + ci.resetMotorPosition(robots[i], 0, false) + "\n");
                jtaInfosDiverses.append(robots[i] + " - LSGetStatus : " + ci.LSGetStatus(robots[i], port) + "\n");
                jtaInfosDiverses.append(robots[i] + " - LSRead : " + ci.LSRead(robots[i], port) + "\n");
                jtaInfosDiverses.append(robots[i] + " - LSWrite : " + ci.LSWrite(robots[i], port, tab, lg) + "\n");

                diTmp = ci.getDeviceInfo(robots[i]);
                jtaInfosDiverses.append(robots[i] + " deviceInfo: " + diTmp.NXTname + "\n");

                fiTmp = ci.getFirmwareVersion(robots[i]);
                jtaInfosDiverses.append(robots[i] + " FirmwareInfo: " + fiTmp.firmwareVersion + "\n");

                jtaInfosDiverses.append(robots[i] + " uploadFile (test2.wav) : " + ci.uploadFile(robots[i], new File("F:/test2.wav"), "test2.wav") + "\n");
                jtaInfosDiverses.append(robots[i] + " uploadFile (test.wav) : " + ci.uploadFile(robots[i], new File("F:/test.wav"), "test.wav") + "\n");
                jtaInfosDiverses.append(robots[i] + " stopSoundPlayback : " + ci.stopSoundPlayback(robots[i])+ "\n");


                jtaInfosDiverses.append(robots[i] + " findFirst : " + ci.findFirst(robots[i], "*.*") + "\n");

                ci.openWrite(nom, "testOpenW", 10);

                FileInfo fi = ci.openRead(nom, "test2.wav");
                jtaInfosDiverses.append("" + fi.fileSize + " " + fi.fileHandle + " " + fi.startPage + " " + fi.status + "\n");
                jtaInfosDiverses.append(robots[i] + " - readFile : " + ci.readFile(robots[i], fi.fileHandle, 10) + "\n");
                jtaInfosDiverses.append(robots[i] + " - closeFile : " + ci.closeFile(robots[i], fi.fileHandle) + "\n");


                jtaInfosDiverses.append(robots[i] + " deleteFile (test2.wav) : " + ci.deleteFile(robots[i], "test2.wav") + "\n");
                jtaInfosDiverses.append(robots[i] + " deleteUserFlash : " + ci.deleteUserFlash(robots[i]) + "\n");
                opTmp = ci.getOutputState(robots[i], 0);

                ci.disconnect(robots[i], adresse);
                jtaInfosDiverses.append(robots[i] + " - disconnect \n");
            } catch (ErreurNXTException ex) {
                Logger.getLogger(JF_TestLib.class.getName()).log(Level.SEVERE, null, ex);
            } catch (IOException ex) {
                Logger.getLogger(JF_TestLib.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    }//GEN-LAST:event_jbAutoTestActionPerformed

    private void jbDeconnexionActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbDeconnexionActionPerformed
        // TODO add your handling code here:
        String robots[] = listeNomRobots.getSelectedItems();

        for (int i = 0; i < robots.length; i++) {
            try {
                ci.disconnect(robots[i]);
                jtaInfosDiverses.append("Deconnexion a " + robots[i] + "\n");
            } catch (IOException ex) {
                Logger.getLogger(JF_TestLib.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    }//GEN-LAST:event_jbDeconnexionActionPerformed

    private void jbRenommerActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbRenommerActionPerformed
        // TODO add your handling code here:
        String robots[] = listeNomRobots.getSelectedItems();
        String nveauNom;


        for (int i = 0; i < robots.length; i++) {
            try {

                if (jTextField1.getText().equals("")) {
                    javax.swing.JOptionPane.showMessageDialog(null, "Veuillez saisir un nom");
                } else {
                    nveauNom = jTextField1.getText();
                    jtaInfosDiverses.append("Renommage de " + robots[i] + " en " + nveauNom + " : " + ci.setFriendlyName(robots[i], nveauNom) + "\n");
                }
            } catch (ErreurNXTException ex) {
                Logger.getLogger(JF_TestLib.class.getName()).log(Level.SEVERE, null, ex);
            } catch (IOException ex) {
                Logger.getLogger(JF_TestLib.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    }//GEN-LAST:event_jbRenommerActionPerformed
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel jLabel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTextField jTextField1;
    private javax.swing.JButton jbA;
    private javax.swing.JButton jbAdr;
    private javax.swing.JButton jbAutoTest;
    private javax.swing.JButton jbB;
    private javax.swing.JButton jbBas;
    private javax.swing.JButton jbClear;
    private javax.swing.JButton jbConnexion;
    private javax.swing.JButton jbDeconnexion;
    private javax.swing.JButton jbDroite;
    private javax.swing.JButton jbEnvoyerFichier;
    private javax.swing.JButton jbGauche;
    private javax.swing.JButton jbHaut;
    private javax.swing.JButton jbPlay;
    private javax.swing.JButton jbRechercheNXT;
    private javax.swing.JButton jbRenommer;
    private javax.swing.JPanel jpWiimote;
    private javax.swing.JTextArea jtaInfosDiverses;
    private java.awt.List listeNomRobots;
    // End of variables declaration//GEN-END:variables
}
